<?

/*
Autor: Imanol Iglesias
email: imanolif@gmail.com
*/


define('APPSECRET_11870', 'xxx');
define('APPTOKEN_11870', 'xxx');
define('USERSLUG_11870', 'user');
define('EMAIL_11870', 'correo');
define('PASSWORD_11870', 'password');

require_once 'Oos.php';

class Servicios11870
{

	public function buscar($q, $location)
	{
		$oos = new Oos();
		$oos->setCredentials(EMAIL_11870, PASSWORD_11870);
		$oos->setUser(USERSLUG_11870);
		$oos->setApiKey(APPTOKEN_11870, APPSECRET_11870);
			
		$s = $oos->search();
		$s->setQueryText($q);
		$s->setLocation($location);
		$sites = $oos->sites();
		$feed = $sites->getSiteFeed($s);
		
		return self::parserServicios($feed);
	}
	
	private function parserServicios($feed)
	{
		$servicios = '';
		
		foreach ($feed as $entry)
		{
			$direccion = $entry->getUserAddress();
			$telefono = $entry->getPhone();
			
			$servicios .= $entry->getTitle();
			
			if (!empty($direccion))
				$servicios .= ': '.$direccion;
				
			if (!empty($telefono))
				$servicios .= ' Tlfno: '.$telefono;
				
			$servicios .= ', ';
		}
		
		return trim($servicios, ', ');
	}

}

/*
$servicios = new Servicios11870();
echo $servicios->buscarServicios('restaurante barato', 'Madrid');
*/

?>